﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Microsoft.Practices.Unity;
using Wms.Data;
using Wms.Repository;
using Wms.Web.Controllers;
using WXML.Model;
using System.Xml;
using System.Web.Hosting;

namespace Wms.Web
{
	// Note: For instructions on enabling IIS6 or IIS7 classic mode, 
	// visit http://go.microsoft.com/?LinkId=9394801

	public class MvcApplication : System.Web.HttpApplication
	{

		private static readonly IUnityContainer _container = new UnityContainer();
		public static IUnityContainer Container
		{
			get { return _container; }
		}


		public static void RegisterRoutes(RouteCollection routes)
		{
			routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

			routes.MapRoute("Entities", "admin/entities/{action}/{entityId}", new { controller = "Entities", action = "Index", entityId = "" });

			routes.MapRoute("Properties",  "admin/properties/{entityId}/{propertyId}/{action}", new {controller = "Property"});

            routes.MapRoute("Default","{controller}/{action}/{id}",new { controller = "Home", action = "Index", id = "" });
			

        }

		protected void Application_Start()
		{
			RegisterRoutes(RouteTable.Routes);
			ControllerBuilder.Current.SetControllerFactory(typeof(WmsControllerFactory));
			Container.RegisterInstance<IDefinitionManager>(new WmsDefinitionManager(HostingEnvironment.MapPath(@"~/App_Data/Meta/")));


            //Wms.Repository.WmsDefinitionManager.GetRepositoryProvider(
            //    System.IO.Path.GetDirectoryName(this.GetType().Assembly.CodeBase), _model);
		}

	}
}
